import { makeAutoObservable } from "mobx";

class UserStore {

  userInfo = {
    name: "test",
    age: 18,
  };
  constructor() {
    makeAutoObservable(this);
  }

  updateUserName(name) {
    this.userInfo.name = name;
  }

  updateUserInfo( userInfo ){
    this.userInfo = userInfo;
  }

  
  async asyncUpdateUserInfo(name) {
  
    const queryNameRes = await queryName(name);
    console.log( queryNameRes );

    //this.userInfo.name = queryNameRes;
    this.updateUserInfo(queryNameRes)
  }
}

function queryName(name){
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        name,
        age:31
      });
    }, 2000);
  });
}

export default UserStore;
